package com.arch.hdfs.tfile;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.MapFile;
import org.apache.hadoop.io.SequenceFile;
import org.apache.hadoop.io.SequenceFile.CompressionType;
import org.apache.hadoop.io.SequenceFile.Writer;
import org.apache.hadoop.io.SequenceFile.Writer.Option;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.io.compress.CompressionCodec;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * 参考连接: https://stackoverflow.com/questions/34243134/what-is-sequence-file-in-hadoop
 *
 * @author pizhihui
 * @date 2024-06-04 17:22
 */
public class SequenceFileDemo {


    public static void main(String[] args) throws IOException {


        System.setProperty("HADOOP_USER_NAME", "biadmin");


        Configuration conf = new Configuration();
        conf.addResource("core-site.xml");
        conf.addResource("hdfs-site.xml");


        Path path = new Path("/tmp/data/seq1");
        FileSystem fs = path.getFileSystem(conf);

        CompressionCodec compressionCodec = null;
        CompressionType compressionType = CompressionType.NONE;

        SequenceFile.Writer writer = SequenceFile.createWriter(fs, conf, path, Text.class, Text.class, compressionType, compressionCodec);

        writer.append(new Text("k1"), new Text("v1"));
        writer.append(new Text("k2"), new Text("v2"));

        writer.hflush();

        writer.close();


    }

}
